package features;

import javax.swing.tree.DefaultMutableTreeNode;

import CAD.MainFrame;
import j3d.InvalidBooleanOperationException;
import operationSolids.CSGSolid;
import operationSolids.CompoundSolid;
import operationSolids.OperationBlock;

public class Step extends Feature{

	
	final static int LEFT =0;
	final static int RIGHT =1;
	final static int TOP =2;
	final static int BOTTOM =3; 
	public float length=0;
	public float width=0;
	public float height=0;
	int side;

	public Step(int type, Feature Mae,float width, float height,int side, String name,int face) {
		super(type, Mae,name);
		this.side=side;
		this.width=width+0.1f;
		this.height=height+0.1f;
		
		create(0, 0, 0, face);
		MainFrame.features.add(this);
		MainFrame.refreshJTree();
		
	}

	@Override
	void translate() {
		switch (side) {		
		case LEFT:
			switch (MainFrame.Face) {
			case MainFrame.TOPFACE:
				feature = new OperationBlock("block",MainFrame.block.length,height,width);
				feature.translate(-MainFrame.block.width/2+(width/2), MainFrame.block.height/2-(height/2),0);
				break;
			case MainFrame.BACKFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(-MainFrame.block.width/2+(width/2), MainFrame.block.length/2-(height/2),0);
				break;
			case MainFrame.LOWERFACE:
				feature = new OperationBlock("block",MainFrame.block.length,height,width);
				feature.translate(-MainFrame.block.width/2+(width/2), MainFrame.block.height/2-(height/2),0);
				break;
			case MainFrame.FRONTFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(-MainFrame.block.width/2+(width/2), MainFrame.block.length/2-(height/2),0);
				break;
			case MainFrame.EASTFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(-MainFrame.block.length/2+(width/2), MainFrame.block.width/2-(height/2),0);
				break;
			case MainFrame.WESTFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(-MainFrame.block.length/2+(width/2), MainFrame.block.width/2-(height/2),0);
				break;
			}
			break;//ok

		case RIGHT:
			switch (MainFrame.Face) {
			case MainFrame.TOPFACE:
				feature = new OperationBlock("block",MainFrame.block.length,height,width);
				feature.translate(MainFrame.block.width/2-(width/2), MainFrame.block.height/2-(height/2),0);
				break;
			case MainFrame.BACKFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(MainFrame.block.width/2-(width/2), MainFrame.block.length/2-(height/2),0);
				break;
			case MainFrame.LOWERFACE:
				feature = new OperationBlock("block",MainFrame.block.length,height,width);
				feature.translate(MainFrame.block.width/2-(width/2), MainFrame.block.height/2-(height/2),0);
				break;
			case MainFrame.FRONTFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(MainFrame.block.width/2-(width/2), MainFrame.block.length/2-(height/2),0);
				break;
			case MainFrame.EASTFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(MainFrame.block.length/2-(width/2), MainFrame.block.width/2-(height/2),0);
				break;
			case MainFrame.WESTFACE:
				feature = new OperationBlock("block",MainFrame.block.height,height,width);
				feature.translate(MainFrame.block.length/2-(width/2), MainFrame.block.width/2-(height/2),0);
				break;
			}
			break;//ok
			
		case TOP:
			switch (MainFrame.Face) {
			case MainFrame.TOPFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.height/2-(height/2),-MainFrame.block.length/2+(width/2));
				break;
			case MainFrame.BACKFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.length/2-(height/2),-MainFrame.block.height/2+(width/2));
				break;
			case MainFrame.LOWERFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.height/2-(height/2),-MainFrame.block.length/2+(width/2));
				break;
			case MainFrame.FRONTFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.length/2-(height/2),-MainFrame.block.height/2+(width/2));
				break;
			case MainFrame.EASTFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.length);
				feature.translate(0, MainFrame.block.width/2-(height/2),-MainFrame.block.height/2+(width/2));
				break;
			case MainFrame.WESTFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.length);
				feature.translate(0, MainFrame.block.width/2-(height/2),-MainFrame.block.height/2+(width/2));
				break;
			}
			break;//ok

		case BOTTOM:
			switch (MainFrame.Face) {
			case MainFrame.TOPFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.height/2-(height/2),MainFrame.block.length/2-(width/2));
				break;
			case MainFrame.BACKFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.length/2-(height/2),MainFrame.block.height/2-(width/2));
				break;
			case MainFrame.LOWERFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.height/2-(height/2),MainFrame.block.length/2-(width/2));
				break;
			case MainFrame.FRONTFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.width);
				feature.translate(0, MainFrame.block.length/2-(height/2),MainFrame.block.height/2-(width/2));
				break;
			case MainFrame.EASTFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.length);
				feature.translate(0, MainFrame.block.width/2-(height/2),MainFrame.block.height/2-(width/2));
				break;
			case MainFrame.WESTFACE:
				feature = new OperationBlock("block",width,height,MainFrame.block.length);
				feature.translate(0, MainFrame.block.width/2-(height/2),MainFrame.block.height/2-(width/2));
				break;
			}
			break;//ok
		}
	}

	@Override
	void compound() {
		MainFrame.block=new Block("comp",CompoundSolid.DIFFERENCE,MainFrame.block,feature);
	}

	@Override
	public void drawNode(DefaultMutableTreeNode node) {
		node.add(
				new DefaultMutableTreeNode(
				"Side:"+toStringSide(side)+"mm")
				);
		node.add(
				new DefaultMutableTreeNode(
				"Length:"+length+"mm")
				);
		node.add(
				new DefaultMutableTreeNode(
				"Width:"+width+"mm")
				);
		node.add(
				new DefaultMutableTreeNode(
				"Height:"+height+"mm")
				);
	}

	private String toStringSide(int side2) {
		switch (side) {
		case LEFT:
			return "Left";
		case RIGHT:
			return "Right";
		case TOP:
			return "Top";
		case BOTTOM:
			return "Bottom";
		default:
			break;
		}
		return "";
	}
	

}








